﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AGMapEditor.Controls
{
    public partial class AGMapEditToolbar : UserControl, IMapPanelObserver
    {
        private AGEMapPanel _ctlMapPanel;

        public AGMapEditToolbar(AGEMapPanel mapPanel)
        {
            InitializeComponent();

            _ctlMapPanel = mapPanel;
            _ctlMapPanel.Attach(this);
        }

        public void UpdateDesignState()
        {
            if (_ctlMapPanel.MapDesignMode == AGMapDesignMode.EditTerrain)
            {
                _ctlBtnSelMode.Text = "地形编辑模式";
                _ctlBtnSelTerrainMode.Checked = true;
                _ctlBtnSelUnitMode.Checked = false;
                _ctlBtnSelBlockMode.Checked = false;
                _ctlBtnSetObjectMode.Checked = false;
            }
            else if (_ctlMapPanel.MapDesignMode == AGMapDesignMode.EditObject)
            {
                _ctlBtnSelMode.Text = "单位编辑模式";
                _ctlBtnSelTerrainMode.Checked = false;
                _ctlBtnSelUnitMode.Checked = true;
                _ctlBtnSelBlockMode.Checked = false;
                _ctlBtnSetObjectMode.Checked = false;
            }
            else if (_ctlMapPanel.MapDesignMode == AGMapDesignMode.EditBlock)
            {
                _ctlBtnSelMode.Text = "障碍编辑模式";
                _ctlBtnSelTerrainMode.Checked = false;
                _ctlBtnSelUnitMode.Checked = false;
                _ctlBtnSelBlockMode.Checked = true;
                _ctlBtnSetObjectMode.Checked = false;
            }
            else if (_ctlMapPanel.MapDesignMode == AGMapDesignMode.SetObject)
            {
                _ctlBtnSelMode.Text = "设置单位模式";
                _ctlBtnSelTerrainMode.Checked = false;
                _ctlBtnSelUnitMode.Checked = false;
                _ctlBtnSelBlockMode.Checked = false;
                _ctlBtnSetObjectMode.Checked = true;
            }

            if (_ctlMapPanel.CurrentTerrain != null)
            {
                _ctlTextCurTerrain.Text = _ctlMapPanel.CurrentTerrain.Caption;
            }
            else
            {
                _ctlTextCurTerrain.Text = "-";
            }

            if (_ctlMapPanel.CurrentTerrainTile != null)
            {
                _ctlTextCurTile.Text = _ctlMapPanel.CurrentTerrainTile.Caption;
            }
            else
            {
                _ctlTextCurTile.Text = "-";
            }

            if (_ctlMapPanel.CurUnit != null)
            {
                _ctlTextSelUnit.Text = _ctlMapPanel.CurUnit.ToString();
            }
            else
            {
                _ctlTextSelUnit.Text = "-";
            }
            _ctlTextPos.Text = string.Format("{0},{1}", _ctlMapPanel.CurPos.X, _ctlMapPanel.CurPos.Y);
        }

        private void _ctlBtnSelUnitMode_CheckedChanged(object sender, EventArgs e)
        {
            if (_ctlBtnSelUnitMode.Checked)
            {
                _ctlMapPanel.SetDesignMode(AGMapDesignMode.EditObject);
            }
        }

        private void _ctlBtnSelTerrainMode_CheckedChanged(object sender, EventArgs e)
        {
            if (_ctlBtnSelTerrainMode.Checked)
            {
                _ctlMapPanel.SetDesignMode(AGMapDesignMode.EditTerrain);
            }
        }

        private void _ctlBtnSelBlockMode_CheckedChanged(object sender, EventArgs e)
        {
            if (_ctlBtnSelBlockMode.Checked)
            {
                _ctlMapPanel.SetDesignMode(AGMapDesignMode.EditBlock);
            }
        }

        private void _ctlBtnSetObjectMode_Click(object sender, EventArgs e)
        {
            if (this._ctlBtnSetObjectMode.Checked)
            {
                _ctlMapPanel.SetDesignMode(AGMapDesignMode.SetObject);
            }
        }

        public void UpdateObjectList()
        {
        }

        public void UpdateSwitchPointList()
        {
        }
    }
}
